import Koa from 'koa';
import convert from 'koa-convert';
import logger from 'koa-logger';
import bodyParser from 'koa-bodyparser';
import Router from '@koa/router';
import cors from '@koa/cors';
import home from './routes/home';

const app = new Koa();
const router = new Router();

router.use(home.routes(), home.allowedMethods());

app
  /* 使用日志中间件 */
  .use(convert(logger()))
  .use(bodyParser())
  .use(cors())
  .use(router.routes())
  .use(router.allowedMethods())
  /* error */
  .on('error', (err: Error) => err)
  .listen(4001);
